package com.kaver.sso.dao.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kaver.sso.dao.mapper.SsoRightsMapper;
import com.kaver.sso.dao.po.SsoRights;
import com.kaver.sso.dao.service.SsoRightsDao;

/**
 * <p>
 * 权限 服务实现类
 * </p>
 *
 * @author roc
 * @since 2021-08-06
 */
@Service
public class SsoRightsDaoImpl extends ServiceImpl<SsoRightsMapper, SsoRights> implements SsoRightsDao {

	@Override
	public boolean queryGroupHasRight(Long groupId, String rightIdentifier) {
		SsoRights query = new SsoRights();
		query.setGroupId(groupId);
		query.setRightIdentifier(rightIdentifier);
		QueryWrapper<SsoRights> queryWrapper = new QueryWrapper<SsoRights>(query);
		int count = this.count(queryWrapper);
		if (count > 0) {
			return true;
		}
		return false;
	}

	@Override
	public int queryGroupRightCount(Long groupId) {
		SsoRights query = new SsoRights();
		query.setGroupId(groupId);
		QueryWrapper<SsoRights> queryWrapper = new QueryWrapper<SsoRights>(query);
		return this.count(queryWrapper);
	}

	@Override
	public List<SsoRights> queryGroupRight(Long groupId) {
		SsoRights query = new SsoRights();
		query.setGroupId(groupId);
		QueryWrapper<SsoRights> queryWrapper = new QueryWrapper<SsoRights>(query);
		return this.list(queryWrapper);
	}

    @Override
    public int queryChildCount(Long parentId) {
        SsoRights query = new SsoRights();
        query.setParentId(parentId);
        QueryWrapper<SsoRights> queryWrapper = new QueryWrapper<SsoRights>(query);
        return this.count(queryWrapper);
    }

}
